DOCUMENTS = seminario-p2p.tex


RM = /bin/rm
ECHO = /bin/echo
EGREP = /bin/egrep
PDFNUP = /usr/bin/pdfnup
PDFLATEX = /usr/bin/pdflatex

PDFLATEX_FLAGS = -interaction=nonstopmode


# TARGETS
all: $(DOCUMENTS:.tex=.pdf)

print: $(DOCUMENTS:.tex=-print.pdf)

notes: $(DOCUMENTS:.tex=-notes.pdf)

multiplex: $(DOCUMENTS:.tex=-print-6up.pdf)

clean:
	-@for ext in aux log out ps toc nav snm dvi vrb ;	\
	do                                              	\
		$(RM) -f *.$$ext ;                      	\
	done

realclean: clean
	-@for ext in pdf ;					\
	do							\
		$(RM) -f *.$$ext ;				\
	done

maintainer-clean: realclean



# relazioni di dipendenza
%-notes.tex: %.tex
	@$(ECHO) '\PassOptionsToClass{notes=only}{beamer}\input{$^}' > $(^:.tex=-notes.tex)

%-print.tex: %.tex
	@$(ECHO) '\PassOptionsToClass{handout}{beamer}\input{$^}' > $(^:.tex=-print.tex)

%.pdf: %.tex
	-@$(PDFLATEX) $(PDFLATEX_FLAGS) $^
	-@latex_count=5 ; 												\
	while $(EGREP) -s 'Rerun (LaTeX|to get cross-references right)' $(^:.tex=.log) && [ $$latex_count -gt 0 ] ;	\
	do 														\
		echo "Rerunning latex...." ;										\
		$(PDFLATEX) $(PDFLATEX_FLAGS) $^ ;									\
		latex_count=`expr $$latex_count - 1` ;									\
	done

%-6up.pdf: %.pdf
	@$(PDFNUP) --nup "3x2"			\
		--offset ".25cm .25cm"		\
		--delta ".25cm .5cm"		\
		--frame true			\
		--scale 0.9			\
		--outfile $(^:.pdf=-6up.pdf)	\
		$^
